<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>视频录制</title>
  <style>
    * {
      margin: 20px;
      box-sizing: border-box;
    }

    #canvas {
      width: 640px;
      height: 480px;
      background: deepskyblue;
      display: block;
      border-radius: 2px;
      box-shadow: 0 1px 1.5px 1px rgba(0, 0, 0, 0.12);
    }

    #button-start {
      width: 300px;
      height: 75px;
      box-sizing: border-box;
      background: linear-gradient(#FF000011, #FF000044) orange;
      color: white;
      font-size: 16px;
      font-family: "monospace";
      border: none;
      outline: none;
      border-radius: 2px;
      box-shadow: 0 1px 1.5px 1px rgba(0, 0, 0, 0.12);
      user-select: none;
    }

    #button-start:hover {
      background: linear-gradient(#FF000033, #FF000077) orange;
    }

    #button-start:active {
      background: linear-gradient(#FF000055, #FF000099) orange;
    }

    #button-start[disabled] {
      background: gray;
    }

    #button-stop {
      width: 300px;
      height: 75px;
      box-sizing: border-box;
      background: linear-gradient(#9933FF00, #9933FF33) dodgerblue;
      color: white;
      font-size: 16px;
      font-family: "monospace";
      border: none;
      outline: none;
      border-radius: 2px;
      box-shadow: 0 1px 1.5px 1px rgba(0, 0, 0, 0.12);
      user-select: none;
    }

    #button-stop:hover {
      background: linear-gradient(#9933FF22, #9933FF66) dodgerblue;
    }

    #button-stop:active {
      background: linear-gradient(#9933FF44, #9933FF88) dodgerblue;
    }

    #button-stop[disabled] {
      background: gray;
    }
  </style>
</head>
<body>
<canvas id="canvas" width="640" height="480"></canvas>
<button id="button-start" >开始录制</button>
<button id="button-stop" disabled>结束录制</button>
<script>
  const $canvas = document.querySelector("#canvas");
  const $video = document.createElement('video');
  const ctx = $canvas.getContext("2d");

  $video.width = 64;
  $video.height = 48;
  $video.src = '../static/demo.mp4';
  $video.muted = true;
  $video.autoplay = true;

  document.body.appendChild($video);

  $video.oncanplay = function () {
    ctx.drawImage($video, 0, 0, 640, 480);
  };

  $video.ontimeupdate = function () {
    //  视频都改变一帧画一帧
    ctx.drawImage($video, 0, 0, 640, 480);
  };
</script>
</body>
</html>
